home *** CD-ROM | disk | FTP | other *** search
/ QuickTime - The Beta Release / QuickTime - The Beta Release.iso / Programming Stuff / Sample Code / BareBones / Bare Bones.c < prev    next >
C/C++ Source or Header  |  1991-09-05  |  3KB  |  115 lines

  1. /**************************************************
  2. *
  3. * Bare Bones Player
  4. *    This program demonstrates how to open a movie file 
  5. *    and play it in a window
  6. *
  7. *     Rich Williams 12/90
  8. *        Updated 2/91, 3/91
  9. *        Updated to 4.04 interfaces 4/91
  10. *    Updated to MPW/Think 5.0/DSG interfaces 9/91 Chris Thorman
  11. *        
  12. ***************************************************/
  13.  
  14. #include "Movies.h"
  15.  
  16. #include <Memory.h>
  17. #include <Fonts.h>
  18. #include <OSEvents.h>
  19. #include <Menus.h>
  20.  
  21. /**************************************************
  22. * Variables
  23. ***************************************************/
  24. Movie    theMovie;                    /*    Info about the movie returned by OpenMovie*/
  25. Rect    dispBounds;
  26.  
  27. WindowPtr    movieWindow;            /* Window to play the movie in */
  28. OSErr        theErr;
  29.  
  30. /* Stuff for opening the file */
  31. FSSpec        mySpec;                    /* File System record for the file */
  32. short        resRefNum;                /* Resource reference number when opening the file */
  33.  
  34. Point        dlgPos = {100,100};        /* Position the dialog box */
  35. Str255         prompt = "\pSelect movie file to play:";
  36. short        numtypes = 1;
  37. SFTypeList    types={'MooV'};
  38.  
  39. SFReply        sfr;
  40.  
  41. void PlayTheMovie(void);
  42.  
  43. /**************************************************
  44. *
  45. * main()
  46. *    This is where everything happens
  47. *
  48. ***************************************************/
  49. main()
  50. {    
  51.     MaxApplZone();                /* Initialize the managers */
  52.     InitGraf(&qd.thePort);
  53.     InitFonts();
  54.     FlushEvents(everyEvent, 0);
  55.     InitWindows();
  56.     InitMenus();
  57.     InitCursor();
  58.  
  59.     if(theErr = EnterMovies())    /* Start up the movie tools */
  60.         return;                    /* Bail out if error. A nice person would put an alert up */
  61.  
  62.     PlayTheMovie();                /* Do it */
  63. }
  64.  
  65. /**************************************************
  66. *
  67. * PlayTheMovie() Opens and plays Movie File
  68. *
  69. ***************************************************/
  70. void 
  71. PlayTheMovie(void)
  72. {
  73.     /* Find out which movie file to play */
  74.  
  75.     SFGetFile( dlgPos, prompt,nil,numtypes,types,nil,&sfr );
  76.     if (!sfr.good) return;                    /* Return if no selection */
  77.     
  78.     /* Now make an FSSpec record of the info */
  79.     theErr = FSMakeFSSpec(sfr.vRefNum,0,sfr.fName,&mySpec);
  80.     
  81.     /* First open the movie file */
  82.     if (theErr = OpenMovieFile(&mySpec, &resRefNum, 0))
  83.         return;                                /* Bail out if it didn't work */
  84.  
  85.     if (theErr = NewMovieFromFile( &theMovie,resRefNum, nil, nil,0, nil ))
  86.         return;                                /* Bail out if it didn't work */
  87.  
  88.     /* Get the bounds for the movie  and make sure the top left is 0,0 */
  89.     /* so the movie won't be offset within the window */
  90.     GetMovieBox( theMovie, &dispBounds);
  91.     OffsetRect(&dispBounds,-dispBounds.left,-dispBounds.top);
  92.     SetMovieBox(theMovie, &dispBounds);        
  93.  
  94.     /* Set up the window for the movie to play in */
  95.     OffsetRect(&dispBounds,100,100);            /* Make sure window not under menu bar */
  96.     movieWindow = NewCWindow(0L,&dispBounds,(StringPtr)sfr.fName,true,0,(WindowPtr)-1L,false,0L);    /* Make a new window */    
  97.     SetPort(movieWindow);
  98.     SetMovieGWorld(theMovie,nil,nil);        /* Play the movie in the window */
  99.     
  100.     /* Now we're ready to play the movie */
  101.     GotoBeginningOfMovie(theMovie);
  102.     PrerollMovie(theMovie,0,0);                /* Get the movie ready to play */
  103.     SetMovieActive(theMovie,true);
  104.     StartMovie(theMovie);                    /* Start the movie */
  105.  
  106.     /* Play the movie until done or the mouse button has been pressed */
  107.     while ( !IsMovieDone(theMovie) && !Button() )
  108.         MoviesTask(theMovie,0);
  109.  
  110.     /* Clean up and go home */
  111.     DisposeMovie(theMovie);                    /* Get rid of the movie */
  112.     CloseMovieFile(resRefNum);
  113. }
  114.  
  115.